﻿using RuoVea.ExDto;
using RuoVea.ExEnum;
using SqlSugar;

namespace RuoVea.Universal.Server.Models;
/// <summary>
/// 元数据字段表。
/// </summary>
public class FieldMetadata : IAuditableEntity
{
    /// <summary>
    /// 主键
    /// </summary>
    [SugarColumn(IsPrimaryKey = true, IsIdentity = false, IsNullable = false)]
    public long Id { get; set; }

    /// <summary>
    /// 获取或设置主键类别。
    /// </summary>
    [SugarColumn(IsNullable = false)]
    public long TableMetaId { get; set; }

    /// <summary>
    /// 获取或设置列名。
    /// </summary>
    public string DbColumnName { get; set; }

    /// <summary>
    /// 获取或设置列的别名。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string ColumnAlias { get; set; }

    /// <summary>
    /// 字段长度
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int Length { get; set; }

    /// <summary>
    /// 获取或设置数据类型。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string DataType { get; set; }

    /// <summary>
    /// 字段描述
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string ColumnDescription { get; set; }

    /// <summary>
    /// 默认值
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public string DefaultValue { get; set; }

    /// <summary>
    /// 获取或设置一个值，指示该列是否允许NULL。
    /// 默认为不允许NULL。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsNullable { get; set; }=false;

    /// <summary>
    /// 获取或设置一个值，指示该列是否为主键。
    /// 默认为非主键。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsPrimarykey { get; set; }=false;

    /// <summary>
    /// 自增
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsIdentity { get; set; }=false;

    /// <summary>
    /// 获取或设置排序号。
    /// 默认为0。
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public int FieldSort { get; set; } = 0;

    /// <summary>
    /// 获取或设置一个值，指示该列是否为系统保留。
    /// 默认为非系统保留。
    /// </summary>
    public bool IsSystemReserved { get; set; } = false;

    /// <summary>
    /// 获取或设置是否为关联字段（用于主从表关联）
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public bool IsRelationField { get; set; } = false;

    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = false)]
    public DateTime? CreateTime { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public long? Creator { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = false)]
    public DateTime? ModifyTime { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = true)]
    public long? Modifier { get; set; }
    /// <summary>
    /// 
    /// </summary>
    [SugarColumn(IsNullable = false)]
    public IsDelete? Deleted { get; set; } = IsDelete.N;
}
